﻿using System.Xml;
using System.IO;
namespace ScaleAnimation
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                System.Console.WriteLine("Usage:\nScaleAnimation infile percentage outfile");
                return;
            }

            string animationPath = args[0];
            float scale = (float)int.Parse(args[1]) / 100.0f;

            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(animationPath);

            XmlNodeList keyframeNodeList = xmlDocument.SelectNodes("Animation/Keyframe");
            foreach (XmlNode keyframeNode in keyframeNodeList)
            {
                XmlNodeList boneNodeList = keyframeNode.SelectNodes("Bone");
                foreach (XmlNode boneNode in boneNodeList)
                {
                    XmlNode positionNodeX = boneNode.SelectSingleNode("Position/X");
                    float x = float.Parse(positionNodeX.InnerText);
                    x *= scale;
                    positionNodeX.InnerText = x.ToString();

                    XmlNode positionNodeY = boneNode.SelectSingleNode("Position/Y");
                    float y = float.Parse(positionNodeY.InnerText);
                    y *= scale;
                    positionNodeY.InnerText = y.ToString();
                }
            }

            xmlDocument.Save(args[2]);
        }
    }
}
